home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / test / iterator.c < prev    next >
C/C++ Source or Header  |  1990-05-19  |  3KB  |  99 lines

  1. /* Test class Iterator
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     K. E. Gorlen
  12.     Bg. 12A, Rm. 2033
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-1111
  18.     uucp: uunet!nih-csl!kgorlen
  19.     Internet:kgorlen@alw.nih.gov
  20.  
  21. Function:
  22.     
  23. Modification History:
  24.     
  25. $Log:    iterator.c,v $
  26.  * Revision 3.0  90/05/20  00:29:20  kgorlen
  27.  * Release for 1st edition.
  28.  * 
  29. */
  30. static char rcsid[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/test/RCS/iterator.c,v 3.0 90/05/20 00:29:20 kgorlen Rel $";
  31.  
  32. #include "Iterator.h"
  33. #include "LinkedList.h"
  34. #include "OrderedCltn.h"
  35. #include "Set.h"
  36. #include "Heap.h"
  37. #include "Point.h"
  38. #include "LinkOb.h"
  39. #include "OIOnih.h"
  40. #include <fcntl.h>
  41. #include <osfcn.h>
  42.  
  43. const char* fileName = "iterator.obj";
  44.  
  45. main()
  46. {
  47.     cout << "\nTest class Iterator" << endl;
  48.     OrderedCltn c,x;
  49.     { for (int j=0; j<6; j++) c.add(*new Point(j,j)); }
  50.     c.dumpOn(cout);  cout.flush();
  51.     Set s;
  52.     s = c.asSet();
  53.     s.dumpOn(cout);  cout.flush();
  54.     LinkedList l;
  55.     Iterator i(s);
  56.     Object* p;
  57.     while (p = i++) l.add(*new LinkOb(*p));
  58.     l.dumpOn(cout);  cout.flush();
  59.     Heap h;
  60.     h = c.asHeap();
  61.     h.dumpOn(cout); cout.flush();
  62.     x.add(c); x.add(l); x.add(h);
  63.  
  64.     DO(x,Collection,cp) {
  65.     cout << "\nTest Iterator(" << cp->className() << ").storeOn()" << endl;
  66.     ostream* out = new ostream(creat(fileName,0664));
  67.     Iterator ii(*cp);
  68.     ii.dumpOn(cout);  cout.flush();
  69.     { for (int j=0; j<3; j++) cout << *ii++; }
  70.     cout << endl;
  71.     ii.dumpOn(cout);  cout.flush();
  72.     ii.storeOn(OIOnihout(*out));
  73.     delete out;
  74.  
  75.     cout << "\nTest Iterator(" << cp->className() << ") readFrom()" << endl;
  76.     istream* in = new istream(open(fileName,O_RDONLY));
  77.     Iterator* ip = Iterator::readFrom(OIOnihin(*in));
  78.     ip->dumpOn(cout);  cout.flush();
  79.     while (p = (*ip)++) cout << *p;
  80.     delete in;
  81.     Collection* tcp=(Collection*)ip->collection();
  82.     delete ip;
  83.     delete tcp;
  84.  
  85.     cout << "\nTest Iterator(" << cp->className() << ").deepCopy()" << endl;
  86.     ip = Iterator::castdown(ii.deepCopy());
  87.     ip->dumpOn(cout);  cout.flush();
  88.     while (p = (*ip)++) cout << *p;
  89.     cout << "\nTest Iterator(" << cp->className() << ").reset()" << endl;
  90.     ip->reset();
  91.     ip->dumpOn(cout);  cout.flush();
  92.     while (p = (*ip)++) cout << *p;
  93.     cout << endl;
  94.     tcp=(Collection*)ip->collection();
  95.     delete ip;
  96.     delete tcp;
  97.     } OD;
  98. }
  99.